<?php
defined('OA_LIB_PATH') || define('OA_LIB_PATH', '/opt/op/OALib');
defined('OPEN_LIB_PATH') || define('OPEN_LIB_PATH', '/opt/op/OpenLib');

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';
require_once OPEN_LIB_PATH . '/open/models/OaCompanyModel.php';

class OaCompanyModelTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_model;
    
    protected function setUp()
    {
        $logger = Log::factory('console', '', '', array(), PEAR_LOG_INFO);
        $this->_logger = $logger;
        $this->_model = new OaCompanyModel($logger);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function testCreateCompany()
    {
        $this->markTestSkipped();
        $result = $this->_model->createCompany('盛大', 'jaggerwang@gmail.com', array('address' => '张江高科居里路208号'));
        $this->assertTrue($result > 0);
        return $result;
    }
    
    /**
     * @depends testCreateCompany
     */
    public function testGetCompany($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompany($companyId);
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        $this->assertTrue(is_array($result));
    }
    
    /**
     * @depends testCreateCompany
     */
    public function testModifyCompany($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->modifyCompany($companyId, array('name' => 'SNDA'));
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider provider
     */
    public function testAddDeveloper($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->addDeveloper($companyId, 1);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider provider
     */
    public function testChangeDeveloperRole($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->changeDeveloperRole($companyId, 1, OaAuthorityModel::ROLE_COMPANY_PM);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider provider
     */
    public function testDeleteDeveloper($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->deleteDeveloper($companyId, 1);
        $this->assertTrue($result);
    }
    
    /**
     * @dataProvider provider
     */
    public function testGetCompanyDeveloperList($companyId)
    {
//        $this->markTestSkipped();
        $result = $this->_model->getCompanyDeveloperList(array(
        	'company_id' => $companyId
        ));
        $this->_logger->info($result);
        $this->assertTrue(is_array($result));
    }
    
    /**
     * @dataProvider provider
     */
    public function testGetCompanyDeveloperListCount($companyId)
    {
//        $this->markTestSkipped();
        $result = $this->_model->getCompanyDeveloperListCount(array(
        	'company_id' => $companyId
        ));
        $this->_logger->info($result);
        $this->assertTrue($result !== false);
    }
    
    /**
     * @dataProvider provider
     */
    public function testGetCompanyApps($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompanyApps($companyId);
        $this->assertTrue(is_array($result));
    }
    
    /**
     * @dataProvider provider
     */
    public function testGetCompanyByIds($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->getCompanyMulti(array(6, 7, 8, $companyId));
        $this->_logger->log($result, PEAR_LOG_DEBUG);
        $this->assertTrue(is_array($result));
    }
    
    /**
     * @dataProvider provider
     */
    public function testInviteSndaUser($companyId)
    {
        $this->markTestSkipped();
        $result = $this->_model->inviteSndaUser('jaggerwang@gmail.com', $companyId, 123);
        $this->assertTrue($result > 0);
        return $result;
    }
    
    public function testAcceptInvite()
    {
        $this->markTestSkipped();
        $inviteId = 1;
        $this->_logger->log($inviteId, PEAR_LOG_DEBUG);
        $result = $this->_model->acceptInvite($inviteId, $this->_model->getInviteToken($inviteId));
        $this->assertTrue($result);
    }
    
    public function provider()
    {
        return array(
            array(1)
        );
    }
}
